package com.ocm.tourism.core.util;


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class TourismUtil {
   public static String createAuditKey(Long businessId, String sessiongId, String loggedUser){
      String auditkey =  businessId + "|" + sessiongId;
      if (loggedUser != null){
         auditkey = auditkey + "|" + loggedUser;
      }
      return auditkey;
   }
   
   public static byte[] convert(InputStream inputStream, int length) throws UnsupportedEncodingException, FileNotFoundException, IOException
   {
     byte[] bytes   = new byte[length];
     int offset     = 0;
     int numRead    = 0;

     // reaf file into byte array
     while (offset < bytes.length && (numRead=inputStream.read(bytes, offset, bytes.length - offset)) >= 0) {
       offset += numRead;
     }

     // errror checking
     if (offset < bytes.length) {
       throw new IOException("Could not completely inputstream ");
     }

     // close input stream
     inputStream.close();

     return bytes;
   }
   
   public static String convert(InputStream inputStream) throws IOException {
      BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
      String str ="";
      StringBuffer content = new StringBuffer();
      while ((str = br.readLine()) != null){
         content.append(str);
      }
      return content.toString();
   }
   
   public static int getNextPage(int page, int nrOfPages){
      if (page < nrOfPages){
         return (page + 1);
      }
      return 0;
   }
}
